package me.ydq.core.table;

import org.springframework.jdbc.core.RowMapper;
import org.springframework.jdbc.core.SingleColumnRowMapper;

import java.util.List;
import java.util.Optional;


/**
 * 查询 top N 数据（LIMIT x)，类似于 list，只是添加参数重载，简化参数
 */
public interface TableTop<T> extends TableList<T> {
    default List<T> top(int size) {
        return list(0, size, rowMapper());
    }

    default <R> List<R> top(int size, RowMapper<R> rowMapper) {
        return list(0, size, rowMapper);
    }

    /**
     * 适合于查询类似于 distinct x 这样的字段
     */
    default <R> List<R> top(int size, Class<R> returnType) {
        return list(0, size, new SingleColumnRowMapper<>(returnType));
    }


}
